package library.base.mvp.module;

import library.base.mvp.IContract;

/**
 * Module对应数据业务逻辑，是按照数据业务划分的（一个Module对应并管理多个Model（数据Bean，可以理解为接口，网络接口，数据库接口等））
 *
 * @author Created by qiang.hou on 2018/5/9.
 * @version 1.0
 */
public abstract class BaseModule implements IContract.IModule {
    /**
     * callback model
     *
     * @param data     model
     * @param observer Observer
     * @param <T>      model type
     * @param <E>      exception type
     */
    @Override
    public <T, E extends Throwable> void notifyModel(T data, IModelObserver<T, E> observer) {
        if (null != observer) {
            observer.onNotify(data);
        }
    }

    /**
     * callback error
     *
     * @param throwable exception
     * @param observer  Observer
     * @param <T>       model type
     * @param <E>       exception type
     */
    @Override
    public <T, E extends Throwable> void notifyError(E throwable, IModelObserver<T, E> observer) {
        if (null != observer) {
            observer.onError(throwable);
        }
    }
}
